package com.simen.hellobytes;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author Created by Simen.
 * @date 创建日期 2018/12/9 17:22
 * @modify 修改者 Simen
 */
public class ProperUtil {

    public static String[] getPropertiesFromRes(String propertyResName, String... keys) throws IOException {
        InputStream inputStream=null;
        try{
            inputStream=AssetsUtil.openResInputStream(propertyResName);

            return getProperties(inputStream,keys);
        }finally {
           IOUtil.closeSilently(inputStream);
        }
    }

    public static String[] getProperties(InputStream inputStream, String... keys) throws IOException {
        if (keys == null || keys.length == 0) {
            return null;
        }

        Properties properties=load(inputStream);

        String[] values = new String[keys.length];
        for (int i = 0; i < keys.length; i++) {
            values[i] = properties.getProperty(keys[i]);
        }

        return values;
    }

    public static Properties load(InputStream inputStream) throws IOException {
        Properties properties = new Properties();
        properties.load(inputStream);
        return properties;
    }

}
